package com.woniu.config;

import com.baidu.aip.contentcensor.AipContentCensor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;

/*
    @Title:
    @Author:Lingger
    @Description:
*/
@Configuration
//加载配置文件
@PropertySource("classpath:baidu.properties")
public class BaiduClientConfig {

    @Resource
    private Environment config;

    @Bean
    public AipContentCensor aipContentCensor() {
        AipContentCensor client = new AipContentCensor(config.getProperty("APP_ID"), config.getProperty("API_KEY"), config.getProperty("SECRET_KEY"));

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 可选：设置log4j日志输出格式，若不设置，则使用默认配置
        // 也可以直接通过jvm启动参数设置此环境变量
//        System.setProperty("aip.log4j.conf", "path/to/your/log4j.properties");

        // 调用接口
        /*String path = "test.jpg";
        JSONObject res = client.imageCensorUserDefined(path);
        System.out.println(res.toString(2));*/
        return client;
    }
}
